1493A - Anti-knapsack - CodeForces Solution


constructive algorithms greedy *800

Please click on ads to support us..

Python Code:

for _ in range(int(input())):
    a, b = map(int, input().split())
    l = []
    for i in range(a, 0, -1):
        if b - i not in l and i != b and sum(l) + i != b:
            l.append(i)
    print(len(l))
    print(*l)

C++ Code:

#include<bits/stdc++.h>
#define ll long long
#define lli long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define test int t ; cin >> t ; while(t--)
#define rep(i,a,b) for (int i = a; i < b; i++)
const ll mod = 1e9 + 7;
using namespace std ;


void solve() {
    int n , k ;
    cin  >> n >> k ;
    cout << n - k + k / 2 << endl;
    for (int i = k + 1 ; i <= n ; i++) {
        cout << i << " " ;
    }
    for (int i = (k + 1) / 2 ; i < k ; i++) {
        cout << i << " " ;
    }
    cout << endl;
}
int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif


    int t;
    cin >> t ;
    while (t--) {
        solve() ;
    };

    return 0 ;
}


Comments

Submit
0 Comments
More Questions

Going to office
Color the boxes
Missing numbers
Maximum sum
13 Reasons Why
Friend's Relationship
Health of a person
Divisibility
A. Movement
Numbers in a matrix
Sequences
Split houses
Divisible
Three primes
Coprimes
Cost of balloons
One String No Trouble
Help Jarvis!
Lift queries
Goki and his breakup
Ali and Helping innocent people
Book of Potion making
Duration
Birthday Party
e-maze-in
Bricks Game
Char Sum
Two Strings
Anagrams
Prime Number